<?php

namespace App\Models;


class Shop extends CommonModel
{
    //
    protected $table = 'shops';

    public function param_options()
    {
        $params = [];
        $params['status'] = [
            "1" => '正常',
            "2" => '暂停'
        ];
        $params['type'] = [
            '1'=>'淘宝店',
            '2'=>'天猫店'
        ];
        return $params;
    }

    /**
     * 店铺下商品
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function products()
    {
        return $this->hasMany(Goods::class, 'shop_id', 'id');
    }

    /**
     * 判断是否存在店铺ID的信息
     *
     * @param $sid
     * @param int $id
     * @return bool
     */
    public static function isExist($sid, $id = 0)
    {
        $data = self::where(['sid' => $sid, 'is_delete' => 0])->when($id, function ($query) use ($id) {
            $query->where('id', '!=', $id);
        })->first();
        return is_null($data) ? false : true;
    }
}
